<style type="text/css">
    .table-madan tr td{background-color: #ffffff;}
    .pihao th{background-color: #ffffff;border-bottom: 2px solid #efefef;}
    .pihao th span{padding: 5px 10px 4px 10px; background-color: #efefef;width: 130px; overflow: visible;font-weight: bold;display:inline-block;font-size: 14px;}
</style>
<div class="change-payment" >
    <div style="overflow:auto;height:500px;width:100%;">
        <table width="100%" cellpadding="0" cellspacing="0" class="finder-header table-madan">
            <tbody>
            <{if $rolls|count gt 0}>
            <input type="hidden" id="goods[product]" value='<{$product_id}>'>
            <input type="hidden" id="goods[clientName]" value='<{$clientName}>'>
                <tr>
                    <td></td>
                    <td class="finder-col-title">
                        <div class="finder-col-label">物品描述</div>    
                    </td>
                    <td class="finder-col-title">
                        <div class="finder-col-label">卷数</div>    
                    </td>
                    <td class="finder-col-title">
                        <div class="finder-col-label">米数</div>    
                    </td>
                </tr>
            <{foreach from=$rolls item=item key=key}>
                <tr>
                    <td>
                        <div class='cell'>
                        <input type="checkbox" class='chk' name="chk[]" id="chk[]" value='<{$item['madan_ids']}>' cnt='<{$item['cntM']}>' cntJuan='<{$item['cntJuan']}>' peihuoCode='<{$item['peihuoCode']}>'>
                        </div>
                    </td>
                    <td><div class='cell'><{$item['peihuoCode']}></div></td>
                    <td><div class='cell'><{$item['cntJuan']}></div></td>
                    <td><div class='cell'><{$item['cntM']}></div></td>
                </tr>
                    
            <{/foreach}>
            <{else}>
                <tr >
                  <th colspan=3>
                    <label><b style='font-size:15px;'>未发现配货单信息！请重新选择</b></label>
                    </th>
                </tr>
            <{/if}>            
            </tbody>
        </table>
    </div>
    <table>
        <tfoot>
            <tr>
                <th colspan="2">
                <button type="button" class="btn btn-caution btnSure"><span><span>确定</span></span></button>
                <span class="label" id='divTotal'></span>
                </th>
            </tr>
        </tfoot>
    </table>

</div>
<script type="text/javascript">
    //每次选中，会重新计算总卷数和总米数
    //1Y = 0.9144M,ec端只考虑米数
    $$('.chk').addEvent('click',function(e){
        var sign = 0;
        var totalCnt=0;
        var totalCntJuan=0;
        var cnt=0;
        var ids= [];
        var peihuoCodes= [];
        var inputs = document.getElementsByName('chk[]');//获取所有的input标签对象。
        for(var i=0;i<inputs.length;i++){
            var obj = inputs[i];
            if(obj.type=='checkbox'){
                if(obj.checked==true){
                    sign++;
                    id = obj.value;
                    peihuoCode = obj.getAttribute("peihuoCode");
                    cnt = parseFloat(obj.getAttribute("cnt"))||0;
                    cntJuan = parseFloat(obj.getAttribute("cntJuan"))||0;
                    totalCnt=parseFloat(totalCnt)+cnt;
                    totalCntJuan=parseFloat(totalCntJuan)+cntJuan;
                    ids.push(id);
                    peihuoCodes.push(peihuoCode);
                }
            }
        }
         //往选中之中填值 
        //合计显示在页面上
        var totalStr="<div type='hidden' id='total' value='"+totalCnt+"' cntJuan='"+totalCntJuan+"' madan_ids='"+ids+"' peihuoCode='"+peihuoCodes+"'></div> ";
        var spanDiv=window.document.getElementById ("divTotal");
        spanDiv.innerHTML = totalStr;
    });

    //2015-9-11 by jeff确认后,ajax访问后台，修改购物车数据后，动态改变当前页面的相关数据
    //包括数量和卷数
    $$('.btnSure').addEvent('click',function(e){
        //往数据库里面填写
        var product_id=window.document.getElementById('goods[product]').value;
        var clientName=window.document.getElementById('goods[clientName]').value;
        var inputCnt = $$('[name="goodsnum['+product_id+']"');
        var inputIds = $$('[name="goodsmadan_ids['+product_id+']"]');
        var inputJu = $$('[name="goodsjuanshu['+product_id+']"]');
        var inputPei = $$('[name="goodsPei['+product_id+']"]');
        var inputCl = $$('[name="goodsClient['+product_id+']"]');
        inputCnt.set('value',window.document.getElementById("total").getAttribute('value'));
        inputIds.set('value',window.document.getElementById("total").getAttribute('madan_ids'));
        inputJu.set('value',window.document.getElementById("total").getAttribute('cntJuan'));
        inputPei.set('value',window.document.getElementById("total").getAttribute('peihuoCode'));
        inputCl.set('value',clientName);
        closeDiv();
        // alert('ajax访问后台，修改购物车数据后，刷新当前页面或者动态改变当前页面的某些区域的数据');
        
    });
</script>
